package day4;

import java.util.Scanner;
//https://www.nowcoder.com/practice/ac61207721a34b74b06597fe6eb67c52?tpId=182&tqId=34617&ru=/exam/oj
public class code1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int flag = 0;
        int num = scanner.nextInt();
        int n = scanner.nextInt();

        String table = "0123456789ABCDEF";
        String ret = "";
        if(num == 0) {
            System.out.println("0");
            return;
        }
        if(num < 0) {
            num = -num;
            flag = 1;
        }
        while (num != 0) {
            ret += table.charAt(num % n);
            num = num / n;
        }
        int i = 0;
        System.out.println(ret);
        if(flag == 1) {
            ret += "-";
        }
        int len = ret.length();
        char[] arr = ret.toCharArray();
        System.out.println(arr);
        reverse(arr,0,len-1);
        System.out.println(ret);

    }
    public static void reverse(char[] arr, int start, int end) {
        while (start < end) {
            char temp = arr[start];
            arr[start] = arr[end];
            arr[end] = temp;
            start++;
            end--;
        }
    }
}
